package data;

import java.util.ArrayList;
import java.util.Date;

public class ListOperator {

	// get list of person that appear in tasks in inputList
	public static ArrayList<Person> getPersonList(ArrayList<Task> inputList) {
		ArrayList<Person> personList = new ArrayList<Person>();
		
		for(Task task : inputList) {
			if(!personList.contains(task.getPerson())) {
				personList.add(task.getPerson());
			}
		}
		
		return personList;
	}
	
	// get list of projects that appear in tasks in inputList
	public static ArrayList<Project> getProjectList(ArrayList<Task> inputList) {
		ArrayList<Project> projectList = new ArrayList<Project>();
		
		for(Task task : inputList) {
			if(!projectList.contains(task.getProject())) {
				projectList.add(task.getProject());
			}
		}
		return projectList;
	}
	
	// get list  of dates that appear in tasks in inputlist
	public static ArrayList<Date> getDateList(ArrayList<Task> inputList) {
		ArrayList<Date> dateList = new ArrayList<Date>();
		
		for(Task task : inputList) {
			if(!dateList.contains(task.getDate())) {
				dateList.add(task.getDate());
			}
		}
		return dateList;
	}
	
	public static ArrayList<Task> filterListByPerson(Person person, ArrayList<Task> inputList) {
		ArrayList<Task> taskByPersonList = new ArrayList<Task>();
		
		for (Task task : inputList) {
			if (task.getPerson() == person) {
				taskByPersonList.add(task);
			}
		}
		return taskByPersonList;
	}
	
	//
	
	public static ArrayList<Task> filterListByProject(Project project, ArrayList<Task> inputList) {
		ArrayList<Task> taskByProjectList = new ArrayList<Task>();
		
		for (Task task : inputList) {
			if (task.getProject() == project) {
				taskByProjectList.add(task);
			}
		}
		return taskByProjectList;
	}
	
	public static ArrayList<Task> filterListByDate(Date date, ArrayList<Task> inputList) {
		ArrayList<Task> taskByDayList = new ArrayList<Task>();
		
		for (Task task : inputList) {
			if (task.getDate() == date) {
				taskByDayList.add(task);
			}
		}
		return taskByDayList;
	}
}